from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-15 14:02:09.190202
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 15, May, 2022
Time: 14:02:15
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.2962
Nobs: 657.000 HQIC: -49.6726
Log likelihood: 8095.55 FPE: 2.10849e-22
AIC: -49.9109 Det(Omega_mle): 1.84046e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.320030 0.060873 5.257 0.000
L1.Burgenland 0.105404 0.038919 2.708 0.007
L1.Kärnten -0.109457 0.020403 -5.365 0.000
L1.Niederösterreich 0.197286 0.081137 2.432 0.015
L1.Oberösterreich 0.122608 0.080173 1.529 0.126
L1.Salzburg 0.256989 0.041348 6.215 0.000
L1.Steiermark 0.044092 0.054258 0.813 0.416
L1.Tirol 0.101270 0.043703 2.317 0.020
L1.Vorarlberg -0.063286 0.038729 -1.634 0.102
L1.Wien 0.030539 0.070938 0.431 0.667
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048801 0.129948 0.376 0.707
L1.Burgenland -0.032197 0.083082 -0.388 0.698
L1.Kärnten 0.040684 0.043555 0.934 0.350
L1.Niederösterreich -0.185220 0.173205 -1.069 0.285
L1.Oberösterreich 0.448453 0.171147 2.620 0.009
L1.Salzburg 0.284633 0.088266 3.225 0.001
L1.Steiermark 0.107832 0.115825 0.931 0.352
L1.Tirol 0.311016 0.093293 3.334 0.001
L1.Vorarlberg 0.022152 0.082677 0.268 0.789
L1.Wien -0.038055 0.151433 -0.251 0.802
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187724 0.031236 6.010 0.000
L1.Burgenland 0.089588 0.019970 4.486 0.000
L1.Kärnten -0.007717 0.010469 -0.737 0.461
L1.Niederösterreich 0.253959 0.041633 6.100 0.000
L1.Oberösterreich 0.155029 0.041139 3.768 0.000
L1.Salzburg 0.042329 0.021216 1.995 0.046
L1.Steiermark 0.024930 0.027841 0.895 0.371
L1.Tirol 0.084741 0.022425 3.779 0.000
L1.Vorarlberg 0.053598 0.019873 2.697 0.007
L1.Wien 0.117081 0.036400 3.217 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111177 0.031345 3.547 0.000
L1.Burgenland 0.045905 0.020041 2.291 0.022
L1.Kärnten -0.014020 0.010506 -1.334 0.182
L1.Niederösterreich 0.183065 0.041780 4.382 0.000
L1.Oberösterreich 0.327719 0.041283 7.938 0.000
L1.Salzburg 0.101490 0.021291 4.767 0.000
L1.Steiermark 0.109967 0.027939 3.936 0.000
L1.Tirol 0.096039 0.022504 4.268 0.000
L1.Vorarlberg 0.059809 0.019943 2.999 0.003
L1.Wien -0.022030 0.036528 -0.603 0.546
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.113952 0.058319 1.954 0.051
L1.Burgenland -0.043580 0.037286 -1.169 0.242
L1.Kärnten -0.046246 0.019547 -2.366 0.018
L1.Niederösterreich 0.141981 0.077732 1.827 0.068
L1.Oberösterreich 0.160648 0.076809 2.092 0.036
L1.Salzburg 0.282037 0.039613 7.120 0.000
L1.Steiermark 0.055884 0.051981 1.075 0.282
L1.Tirol 0.165079 0.041869 3.943 0.000
L1.Vorarlberg 0.095607 0.037104 2.577 0.010
L1.Wien 0.076845 0.067961 1.131 0.258
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061642 0.046022 1.339 0.180
L1.Burgenland 0.031192 0.029424 1.060 0.289
L1.Kärnten 0.051413 0.015426 3.333 0.001
L1.Niederösterreich 0.206911 0.061342 3.373 0.001
L1.Oberösterreich 0.316822 0.060613 5.227 0.000
L1.Salzburg 0.041096 0.031260 1.315 0.189
L1.Steiermark 0.006633 0.041020 0.162 0.872
L1.Tirol 0.131323 0.033040 3.975 0.000
L1.Vorarlberg 0.065899 0.029281 2.251 0.024
L1.Wien 0.087948 0.053631 1.640 0.101
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174307 0.055201 3.158 0.002
L1.Burgenland 0.005045 0.035293 0.143 0.886
L1.Kärnten -0.065180 0.018502 -3.523 0.000
L1.Niederösterreich -0.097547 0.073577 -1.326 0.185
L1.Oberösterreich 0.204287 0.072703 2.810 0.005
L1.Salzburg 0.054096 0.037495 1.443 0.149
L1.Steiermark 0.242162 0.049202 4.922 0.000
L1.Tirol 0.500781 0.039631 12.636 0.000
L1.Vorarlberg 0.058180 0.035121 1.657 0.098
L1.Wien -0.073533 0.064329 -1.143 0.253
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149282 0.061224 2.438 0.015
L1.Burgenland 0.003970 0.039143 0.101 0.919
L1.Kärnten 0.060266 0.020521 2.937 0.003
L1.Niederösterreich 0.180097 0.081604 2.207 0.027
L1.Oberösterreich -0.056507 0.080635 -0.701 0.483
L1.Salzburg 0.205861 0.041586 4.950 0.000
L1.Steiermark 0.134691 0.054570 2.468 0.014
L1.Tirol 0.069238 0.043954 1.575 0.115
L1.Vorarlberg 0.143750 0.038952 3.690 0.000
L1.Wien 0.111223 0.071347 1.559 0.119
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.375446 0.036080 10.406 0.000
L1.Burgenland -0.000692 0.023067 -0.030 0.976
L1.Kärnten -0.021619 0.012093 -1.788 0.074
L1.Niederösterreich 0.214673 0.048090 4.464 0.000
L1.Oberösterreich 0.227082 0.047519 4.779 0.000
L1.Salzburg 0.038555 0.024507 1.573 0.116
L1.Steiermark -0.014590 0.032159 -0.454 0.650
L1.Tirol 0.093304 0.025903 3.602 0.000
L1.Vorarlberg 0.054280 0.022955 2.365 0.018
L1.Wien 0.035495 0.042045 0.844 0.399
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036680 0.116023 0.173530 0.142446 0.100179 0.084331 0.039394 0.210964
Kärnten 0.036680 1.000000 -0.019723 0.134896 0.052338 0.090090 0.440619 -0.060560 0.093768
Niederösterreich 0.116023 -0.019723 1.000000 0.324352 0.128379 0.285180 0.073311 0.161844 0.297760
Oberösterreich 0.173530 0.134896 0.324352 1.000000 0.220848 0.309278 0.167605 0.150278 0.251461
Salzburg 0.142446 0.052338 0.128379 0.220848 1.000000 0.129595 0.097769 0.114972 0.129738
Steiermark 0.100179 0.090090 0.285180 0.309278 0.129595 1.000000 0.138236 0.118145 0.051009
Tirol 0.084331 0.440619 0.073311 0.167605 0.097769 0.138236 1.000000 0.069532 0.146471
Vorarlberg 0.039394 -0.060560 0.161844 0.150278 0.114972 0.118145 0.069532 1.000000 0.006525
Wien 0.210964 0.093768 0.297760 0.251461 0.129738 0.051009 0.146471 0.006525 1.000000